<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据集合')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: container-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>
</head>
<style>
    .inputs {
        width: 45% !important;
        float: right;
        margin-bottom: 10px;

    }

    .modal-body {
        padding: 15px !important;
    }

    .modal-contents {
        width: 482px !important;
    }

</style>
<body class="gray-bg">

<div class="modal inmodal fade" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content modal-contents">

            <div class="modal-body">
                <p>
                    <label>薪资期间:</label><br/>
                    <input type="text" name="termNo" class="form-control inputs" id="termNo"
                           required disabled="disabled">
                    <input type="text" name="term" class="form-control inputs" id="term"
                           required style="float: left;">
                </p>
                <p>
                    <label>薪资区间:</label><br/>
                    <input type="text" name="endDate" class="form-control inputs" id="endDate"
                           required>
                    <input type="text" name="startDate" class="form-control inputs" id="startDate"
                           required style="float: left;">
                    <span style="margin-left: 10px;">— —</span>

                </p><br/>
                <p>
                    <label>接口区间:</label><br/>
                    <input type="text" name="endDateA" class="form-control inputs" id="endDateA"
                           required>
                    <input type="text" name="startDateA" class="form-control inputs" id="startDateA"
                           required style="float: left;">
                    <span style="margin-left: 10px;">— —</span>

                </p><br/>
                <p>
                    <label><input type="checkbox" checked="checked" name="ReserveData" id="ReserveData"
                                  style="float: left; margin-top: 1.5px;">保留当前数据</label>
                    <label style="margin-left: 199px;"><input type="checkbox" style="float: left; margin-top: 1.5px;">初始化之后计算所有项目</label>
                </p>
                <p>
                    <label>提示信息:</label>
                    <textarea style="resize:none;" id="remark" name="remark" class="form-control"
                              placeholder="准备就绪，请按[初始化] 完成操作"></textarea>
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" id="missmodal2" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" onclick="Initialization()" class="btn btn-primary">初始化</button>
            </div>
        </div>
    </div>
</div>


<button type="button" id="modal2" class="btn btn-primary" data-toggle="modal"
        data-target="#myModal2">初始化窗口
</button>


<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="ComPidorDepTid" name="ComPidorDepTid">
                    <div class="select-list">
                        <ul>
                            <li>
                                员工编号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped" id="ry">
                <div class="btn-group-sm" role="group">
                    <button type="button" class="btn btn-primary" id="initialized" onclick="PreInitialization()"><i
                            class="fa fa-edit"></i> 初始化
                    </button>
                    <button type="button" class="btn btn-warning" id="submit"
                            onclick="executeProcedure('submitBefore')"><i class="fa fa-download"></i> 计算
                    </button>
                    <button type="button" class="btn btn-info" id="frozen" onclick="executeProcedure('freeze')"><i
                            class="fa fa-paste"></i> 冻结
                    </button>
                    <button type="button" class="btn btn-danger" id="cancelFrozen" onclick="executeProcedure('cancel')">
                        <i class="fa fa-remove"></i> 取消冻结
                    </button>
                    <button type="button" class="btn btn-warning" id="closed" onclick="executeProcedure('closed')"><i
                            class="fa fa-download"></i> 封账
                    </button>

                    <a class="btn btn-warning" onclick="$.operate.exportSalaryData(pgid)"
                       shiro:hasPermission="system:benefitbase:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>


                <table id="salaryCalculation-table" data-mobile-responsive="true"></table>
                <div class="fixed-table-loading" style="top: 41px; display: none;">正在努力地加载数据中，请稍候……</div>
            </div>
        </div>
    </div>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<script th:inline="javascript">
    var pgid;
    var prefix = ctx + "salaryCalculation";

    $(function () {
        pgid = [[${pgid}]];
        $("#modal2").hide();
        refreshButton(pgid);
        queryEmpSalaryInfoList();
    });

    //获取数据集合
    function queryEmpSalaryInfoList() {
        var columns = [];
        var time = {field: '时间', title: '时间', sortable: true};
        var badge = {field: 'badge', title: '员工编号', sortable: true};
        var name = {field: 'name', title: '姓名', sortable: true};
        var compName = {field: '公司名称', title: '公司名称', sortable: true};
        var depName = {field: '部门名称', title: '部门名称', sortable: true};
        var jobName = {field: '岗位名称', title: '岗位名称', sortable: true};
        var empStatus = {field: '在岗状态', title: '在岗状态', sortable: true};
        var empStartDate = {field: 'EmpStartDate', title: '入职日期', sortable: true};
        var empEndDate = {field: 'EmpEndDate', title: '离职日期', sortable: true};
        columns.push(time, badge, name, compName, depName, jobName, empStatus, empStartDate, empEndDate);
        var other;
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/getPro",
            data: {"pgid": pgid},
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    other = {
                        field: data[i], title: data[i], sortable: true
                    }
                    columns.push(other);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });

        var options = {
            id: "salaryCalculation-table",
            code: "eid",
            uniqueId: "eid",
            url: prefix + "/list?pgid=" + pgid,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            exportUrl: prefix + "/export?pgid=" + pgid,
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            pagination: false,
            showColumns: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            modalName: "基本信息",
            height: $(window).height() - 120,
            onLoadSuccess: function () {

                $(".th-inner").click(function () {
                    $(".fixed-table-loading").show();
                    setTimeout(function () {
                        $(".fixed-table-loading").hide();
                    }, 1000);
                });
            },
            columns: columns
        };
        $.table.init(options);
    }

    //获取初始化窗口时间
    function PreInitialization() {
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/findNewTerm",
            data: {"pgid": pgid},
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.code == 0) {
                    $("#term").val(data.data.term);
                    $("#termNo").val(data.data.termNo);
                    $("#startDate").val(data.data.StartDate);
                    $("#endDate").val(data.data.enddate);
                    $("#startDateA").val(data.data.StartDateA);
                    $("#endDateA").val(data.data.enddateA);
                } else {
                    $.modal.alertWarning(data.message);
                }
                $("#modal2").click();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    //执行初始化
    function Initialization() {
        var term = $("#term").val();
        var ReserveData = $('#ReserveData').is(':checked');
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/executeProcedure",
            data: {"pgid": pgid, "term": term, "reserveData": ReserveData, "type": "init"},
            type: "post",
            dataType: "text",
            success: function (data) {
                refreshButton(pgid);
                $.modal.alertSuccess(data);
                $("#missmodal2").click();
                $("#salaryCalculation-table").bootstrapTable('refresh');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    //执行初始化
    function executeProcedure(type) {
        var term = $("#term").val();
        var ReserveData = $('#ReserveData').is(':checked');
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/executeProcedure",
            data: {"pgid": pgid, "term": term, "reserveData": ReserveData, "type": type},
            type: "post",
            dataType: "text",
            success: function (data) {
                refreshButton(pgid);
                $.modal.alertSuccess(data);
                $("#salaryCalculation-table").bootstrapTable('refresh');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function refreshButton() {
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/refreshButton",
            data: {"pgid": pgid},
            type: "post",
            dataType: "json",
            success: function (data) {
                //未初始化
                console.log(data);
                var initialized = data.initialized;
                var submit = data.submit;
                var frozen = data.frozen;
                var closed = data.closed;
                if (initialized == false && submit == false && frozen == false && closed == false) {
                    //未初始化
                    $("#initialized").attr('disabled', false);
                    $("#submit").attr('disabled', true);
                    $("#frozen").attr('disabled', true);
                    $("#cancelFrozen").attr('disabled', true);
                    $("#closed").attr('disabled', true);
                } else if (initialized == true && submit == false && frozen == false && closed == false) {
                    //刚初始化
                    $("#initialized").attr('disabled', false);
                    $("#submit").attr('disabled', false);
                    $("#frozen").attr('disabled', true);
                    $("#cancelFrozen").attr('disabled', true);
                    $("#closed").attr('disabled', true);
                }
                else if (initialized == true && submit == true && frozen == false && closed == false) {
                    //已计算或取消冻结
                    $("#initialized").attr('disabled', false);
                    $("#submit").attr('disabled', false);
                    $("#frozen").attr('disabled', false);
                    $("#cancelFrozen").attr('disabled', true);
                    $("#closed").attr('disabled', true);
                }
                else if (initialized == true && submit == true && frozen == true && closed == false) {
                    //已冻结
                    $("#initialized").attr('disabled', false);
                    $("#submit").attr('disabled', true);
                    $("#frozen").attr('disabled', true);
                    $("#cancelFrozen").attr('disabled', false);
                    $("#closed").attr('disabled', false);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

</script>
</body>
</html>